#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
constexpr int N=2e5+5;
namespace FastIO{
    const int BUF_SIZ=1<<16;
    char in_buf[BUF_SIZ],*got_pos=in_buf,*read_pos=in_buf,out_buf[BUF_SIZ],*write_pos=out_buf;
    inline char get_next_char(){if(read_pos==got_pos){got_pos=read_pos=in_buf;got_pos+=fread(got_pos,sizeof(char),BUF_SIZ,stdin);}return*(read_pos++);}
    inline void flush_output(){fwrite(out_buf,sizeof(char),write_pos-out_buf,stdout);write_pos=out_buf;}
    inline void put_char(char ch){*(write_pos++)=ch;if(write_pos==out_buf+BUF_SIZ)flush_output();}
#ifndef FASTIO_READ_NEGATIVE
    template<typename T> inline void read(T& res){char ch;while(!isdigit(ch=get_next_char()));res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');}
#else
    template<typename T> inline void read(T& res){char ch;bool flg=0;while(!isdigit(ch=get_next_char()))flg|=ch=='-';res=ch^'0';while(isdigit(ch=get_next_char()))res=(res<<3)+(res<<1)+(ch^'0');if(flg)res=-res;}
#endif
    template<typename T> inline void write(T x){if(!x){put_char('0');return;}static int lis[25],*lp=lis;while(x){*(++lp)=x%10;x/=10;}while(lp!=lis)put_char((*(lp--))+'0');}
    template<typename T> inline void writeln(const T& x){write(x);put_char('\n');}
    template<typename T> inline void writesp(const T& x){write(x);put_char(' ');}
    class _IO_Flusher{public:~_IO_Flusher(){flush_output();}}__Flusher;
    class IStream{public:
        template<typename T> inline IStream& operator>>(T& x){read(x);return *this;}
        inline IStream& operator>>(char* str){char ch;while(isspace(ch=get_next_char()));(*(str++))=ch;while(!isspace(ch=get_next_char())){if(ch==EOF)break;(*(str++))=ch;}*str=0;return *this;}
    }Cin;
    class OStream{public:
        template<typename T> inline enable_if_t<is_integral<T>::value,OStream&> operator<< (const T& x){write(x);return *this;}
        inline OStream& operator<< (const char& ch){put_char(ch);return *this;}
        inline OStream& operator<< (const char* str){for(const char* p=str;*p;put_char(*(p++)));return *this;}
    }Cout;
}
using namespace FastIO;
#define cin Cin
#define cout Cout
class DSU{
	int n,cnt,fa[N],siz[N],st[N],tp;
public:
	void init(int _n) { n=_n; cnt=n; For(i,1,n) fa[i]=i,siz[i]=1; }
	int getfa(int x) { while(x!=fa[x]) x=fa[x];; return x; }
	void merge(int x,int y) {
		x=getfa(x); y=getfa(y); if(x==y) { st[++tp]=0; return; }
		if(siz[x]<siz[y]) swap(x,y);
		fa[y]=x; siz[x]+=siz[y]; st[++tp]=y; cnt--;
	}
	void undo(){
		int y=st[tp--]; if(y) siz[fa[y]]-=siz[y],fa[y]=y,cnt++;
	}
	bool check() { return cnt==1; }
}O;
int n,m,Q,lst[N],A[N],B[N],ans[N]; vector<int> lis[N<<2];
#define k1 (k<<1)
#define k2 (k<<1|1)
void add(int k,int l,int r,int ql,int qr,int e){
	if(ql<=l&&r<=qr) return lis[k].push_back(e),void();
	int mid=(l+r)>>1;
	if(ql<=mid) add(k1,l,mid,ql,qr,e);
	if(mid+1<=qr) add(k2,mid+1,r,ql,qr,e);
}
void dfs(int k,int l,int r){
	int flg=0;
	if(!O.check()){
		flg=1; for(int e:lis[k]) O.merge(A[e],B[e]);
	}
	if(l==r) { if(ans[l]==0) ans[l]=O.check(); else ans[l]=0; }
	else { int mid=(l+r)>>1; dfs(k1,l,mid),dfs(k2,mid+1,r); }
	if(flg){
		for(int e:lis[k]) O.undo();
	}
}
int main(){
	Fin("graph.in"); Fout("graph.out");
	// ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m; For(i,1,m) cin>>A[i]>>B[i];
	O.init(n); cin>>Q;
	For(i,1,Q){
		int K; cin>>K;
		if(K>m-n+1) { ans[i]=-1; For(_,1,K) { int e; cin>>e; } }
		else { For(_,1,K) { int e; cin>>e; if(lst[e]!=i-1) add(1,1,Q,lst[e]+1,i-1,e);; lst[e]=i; } }
	}
	For(e,1,m) if(lst[e]!=Q) add(1,1,Q,lst[e]+1,Q,e);
	// cerr<<"hey "<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
	dfs(1,1,Q); For(i,1,Q) cout<<(ans[i]?"YES\n":"NO\n");
	return 0;
}